package com.qingcheng.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.order.Order;
<<<<<<< HEAD
import com.qingcheng.pojo.order.OrderIterms;
=======
import com.qingcheng.pojo.order.OrderItem;
>>>>>>> origin/jtt
import com.qingcheng.service.order.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;
    
    @GetMapping("/findAll")
    public List<Order> findAll(){
        return orderService.findAll();
    }
    
    @GetMapping("/findPage")
    public PageResult<Order> findPage(int page, int size){
        return orderService.findPage(page, size);
    }
    
    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String,Object> searchMap){
        return orderService.findList(searchMap);
    }
    
    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  orderService.findPage(searchMap,page,size);
    }
    
    @GetMapping("/findById")
    public Order findById(String id){
        return orderService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        orderService.add(order);
        return new Result();
    }
    
    @PostMapping("/update")
    public Result update(@RequestBody Order order){
        orderService.update(order);
        return new Result();
    }
    
    @GetMapping("/delete")
    public Result delete(String id){
        orderService.delete(id);
        return new Result();
    }
<<<<<<< HEAD
    
    /**
     * 根据订单id查询订单详情
     * @param id 订单id 
     * @return 此订单的所有数据
     */
    @GetMapping("/findOrderItemsById")
    public OrderIterms findOrderItemsById(String id){ 
        return orderService.findOrderItemsById(id); 
    }

    /**
     * 订单合并
     * */
    @GetMapping("/merge")
    public Result merge(String orderId1, String orderId2){
        Map<Integer, String> map = orderService.mergeOrder(orderId1, orderId2);
        Set<Integer> set = map.keySet();
        int code=1;
        String message="";
        for (Integer key : set) {
           code=key;
           message=map.get(key);
        }
        return new Result(code,message);
=======
    @PostMapping("/split")
    public Result split(@RequestBody List<OrderItem> orderItemList){
        try {
            orderService.split(orderItemList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1,e.getMessage());
        }
        return new Result();
>>>>>>> origin/jtt
    }


    @PostMapping("/findStatusById")
    public List<Order> findStatusById(@RequestBody Map<String,Object> searchMap){
        return orderService.findStatusById(searchMap);
    }

    @PostMapping("/updateOrderLog")
    public Result updateOrderLog(@RequestBody List<Order> orderList){
        orderService.updateOrderLog(orderList);
        return new Result();
    }

}
